package com.robbierobin1.theandroidproject;


import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	public int counter;
	TextView tv;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		//create textview
		counter = 0;
		tv = (TextView) findViewById(R.id.counter);
	}
	/**
	 * simple method to update the counter
	 */
	public void updateView(){
		tv.setText(Integer.toString(counter));
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	/**
	 * Simple method to check if the number is valid.
	 */
	public void checkNumber(){
		if(counter <= 0){
			counter = 0;
		}
	}
	
	/**
	 * Simple method to increment the Counter by one
	 * @param view
	 */
	public void incrementOne(View view){
		counter++;
		checkNumber();
		updateView();
	}
	/**
	 * Simple method to decrement the counter by one
	 * @param view
	 */
	public void decrementOne(View view){
		counter--;
		checkNumber();
		updateView();
	}
	/**
	 * Simple method to increment the counter by ten
	 * @param view
	 */
	public void incrementTen(View view){
		counter+=10;
		checkNumber();
		updateView();
	}
	
	/**
	 * Simple method to decrement the counter by 10
	 * @param view
	 */
	public void decrementTen(View view){
		counter-=10;
		checkNumber();
		updateView();
	}
	
	/**
	 * Simple method to reset the counter
	 * @param view
	 */
	public void resetCounter(View view){
		counter = 0;
		updateView();
	}
	
}
